#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>
#include <errno.h>

int rename_func_test()
{
    int flag = 0;
    int oldfd, newfd;
    printf("---- test rename start----\n");
    errno = 0;
    if ((flag = rename("123", "456")) == -1)
    {
        perror("rename failded!");
    }
    printf("---- test rename end----\n");

    printf("---- test renameat start----\n");
    errno = 0;
    if ((oldfd = open("test1", O_PATH)) == -1)
    {
        perror("test1 file open error");
        return 0;
    }

    if ((newfd = open("test2", O_PATH)) == -1)
    {
        perror("test2 file creat error");
        return 0;
    }

    errno = 0;
    if ((flag = renameat(oldfd, "test", newfd, "test-rename")) == -1)
    {
        perror("renameat failded!");
    }

    printf("---- test renameat end----\n");

    return 0;
}

int main(int argc, char const *argv[])
{
    (void)rename_func_test();
    return 0;
}
//gcc rename_test.c -D_GNU_SOURCE